#include "mainwindow.h"
#include "requetes.h"
#include "searchinblobs.h"
#include "ficheannuelle.h"

#include <QDebug>

MainWindowRequete::MainWindowRequete() : m_file(0),m_actions(0),m_fermer(0),m_requete(0)
{
    setupUi(this);
    setAttribute(Qt::WA_DeleteOnClose);
    createMenus();
    createActions();
    connectActions();
}

MainWindowRequete::~MainWindowRequete(){
    qWarning() << __FILE__ << QString::number(__LINE__) << "in mainwindow destructor" ;
}


void MainWindowRequete::createMenus()
{
    m_file = menuBar()->addMenu(tr("&Fichier"));
    m_actions = menuBar()->addMenu(tr("&Actions"));
}

void MainWindowRequete::createActions()
{
    m_fermer = m_file->addAction(trUtf8("&Quitter"));
    m_fermer->setShortcut(QKeySequence::Close);
    m_requete = m_actions->addAction(trUtf8("&Requête"));
    m_searchinblobs = m_actions->addAction(trUtf8("&Chercher dans les données"));
    m_ficheannuelle = m_actions->addAction(trUtf8("Produire la fiche annuelle patient"));
}

void MainWindowRequete::connectActions()
{
    connect(m_fermer,SIGNAL(triggered()), this, SLOT(close()));
    connect(m_requete,SIGNAL(triggered()), this, SLOT(runRequete()));
    connect(m_searchinblobs,SIGNAL(triggered()),this,SLOT(runSearchinblobs()));    
    connect(m_ficheannuelle,SIGNAL(triggered()),this,SLOT(runAnnualResearch()));    
}

void MainWindowRequete::runRequete()
{
    Requete * requete = new Requete(this);
    setCentralWidget(requete);
}

void MainWindowRequete::runSearchinblobs()
{
    Searchinblobs* search = new Searchinblobs(this);
    search->setMedintuxUser(m_user);
    search->initialise();
    setCentralWidget(search);
}

void MainWindowRequete::runAnnualResearch()
{
    FicheAnnuelle * ficheannuelle = new FicheAnnuelle(this);
    ficheannuelle->setInformations(m_name,m_firstname,m_guid,m_user);
    setCentralWidget(ficheannuelle);
}

void MainWindowRequete::setInformations(const QString & name, const QString & firstname, const QString & guid, const QString & user)
{
    m_name = name;
    m_firstname = firstname;
    m_guid = guid;
    m_user = user;
}

void MainWindowRequete::runAnnualResearchWidget()
{
        runAnnualResearch();
}


